﻿CREATE VIEW [dbo].[v_BuyersOrder_30]
AS
SELECT     dbo.v_BuyersOrder_20.LoanID, dbo.v_BuyersOrder_20.DealerID, dbo.v_BuyersOrder_20.DealerSalesPersonID, dbo.v_BuyersOrder_20.StatusID, 
                      dbo.v_BuyersOrder_20.Status, dbo.v_BuyersOrder_20.VerificationStatusID, dbo.v_BuyersOrder_20.Status_Verification, 
                      dbo.v_BuyersOrder_20.ContractHolderID, dbo.v_BuyersOrder_20.SalesPrice, dbo.v_BuyersOrder_20.VIN, dbo.v_BuyersOrder_20.BookValue, 
                      dbo.v_BuyersOrder_20.BookValueDesc, dbo.v_BuyersOrder_20.ModelAge, dbo.v_BuyersOrder_20.Mileage, dbo.v_BuyersOrder_20.MilesPerYear, 
                      dbo.v_BuyersOrder_20.SalesTaxPercent, ISNULL(dbo.v_BuyersOrder_20.SalesTaxAmount, CONVERT(numeric(38, 2), 
                      dbo.v_BuyersOrder_20.UnpaidBalance * dbo.v_BuyersOrder_20.SalesTaxPercent)) AS SalesTaxAmount, 
                      dbo.v_BuyersOrder_20.Lamp_SalesTaxPercent, dbo.v_BuyersOrder_20.Lamp_SalesTaxAmount, dbo.v_BuyersOrder_20.DownPayment, 
                      dbo.v_BuyersOrder_20.DealerFee, dbo.v_BuyersOrder_20.TaxableFees, dbo.v_BuyersOrder_20.TradeIn, dbo.v_BuyersOrder_20.UnpaidBalance, 
                      dbo.v_BuyersOrder_20.UnPaidBalanceWithTax, dbo.v_BuyersOrder_20.Lamp_UnPaidBalanceWithTax, dbo.v_BuyersOrder_20.GAP, 
                      dbo.v_BuyersOrder_20.ServiceContract, dbo.v_BuyersOrder_20.NonTaxableFees, dbo.v_BuyersOrder_20.TagFee, 
                      dbo.v_BuyersOrder_20.APROverride, dbo.v_BuyersOrder_20.LoanTerm, dbo.v_BuyersOrder_20.ContractDate, 
                      dbo.v_BuyersOrder_20.FirstPaymentDate, dbo.v_BuyersOrder_20.AddOnRateOverride, dbo.v_BuyersOrder_20.PaymentOverride, 
                      dbo.v_BuyersOrder_20.NumberOfPayments, dbo.v_BuyersOrder_20.IsRule78, dbo.v_BuyersOrder_20.IsSUV, dbo.v_BuyersOrder_20.TrackerTypeID, 
                      dbo.v_BuyersOrder_20.IsIndependent, dbo.v_BuyersOrder_20.PaymentsPerYear, dbo.v_BuyersOrder_20.PaymentTypeID, 
                      dbo.v_BuyersOrder_20.InterestType, dbo.v_BuyersOrder_20.DayCountConventionID, dbo.v_BuyersOrder_20.PrincipalBalance, 
                      dbo.v_BuyersOrder_20.BookValueCurrent, dbo.v_BuyersOrder_20.BookValueCurrentTypeID, dbo.v_BuyersOrder_20.DealerState, 
                      dbo.v_BuyersOrder_20.ContractHolderState
, CONVERT(varchar,
		COALESCE (
			NULLIF (LTRIM(dbo.v_BuyersOrder_20.DealerState), '')
		, NULLIF (LTRIM(A.StateCode), '')
		, NULLIF(LTRIM(dbo.v_BuyersOrder_20.ContractHolderState),'')
		, ''
		)
	) AS LoanState
                      , dbo.v_BuyersOrder_20.CarYear, dbo.v_BuyersOrder_20.GUID_Documents, 
                      dbo.v_BuyersOrder_20.StatusID_Repo, dbo.v_BuyersOrder_20.StatusUser_Repo, dbo.v_BuyersOrder_20.StatusDate_Repo, 
                      dbo.v_BuyersOrder_20.Status_Repo, dbo.v_BuyersOrder_20.StatusID_BK, dbo.v_BuyersOrder_20.StatusUser_BK, 
                      dbo.v_BuyersOrder_20.StatusDate_BK, BookValueCurrentDate, BookValueProviderCode

FROM         dbo.v_BuyersOrder_20 INNER JOIN
                      dbo.t_Loan_Borrower AS L_B ON L_B.LoanID = dbo.v_BuyersOrder_20.LoanID INNER JOIN
                      dbo.t_Address AS A ON A.BorrowerID = L_B.BorrowerID
WHERE     (L_B.Pos = 0) AND (A.Pos = 0)



GO
EXECUTE sp_addextendedproperty @name = N'MS_DiagramPane1', @value = N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[23] 4[54] 2[5] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1[50] 4[25] 3) )"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1[20] 4) )"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "v_BuyersOrder_20"
            Begin Extent = 
               Top = 6
               Left = 38
               Bottom = 235
               Right = 259
            End
            DisplayFlags = 280
            TopColumn = 47
         End
         Begin Table = "L_B"
            Begin Extent = 
               Top = 20
               Left = 343
               Bottom = 113
               Right = 494
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "A"
            Begin Extent = 
               Top = 67
               Left = 555
               Bottom = 287
               Right = 721
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
      Begin ColumnWidths = 53
         Width = 284
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Wid', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'VIEW', @level1name = N'v_BuyersOrder_30';


GO
EXECUTE sp_addextendedproperty @name = N'MS_DiagramPane2', @value = N'th = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 9990
         Alias = 900
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'VIEW', @level1name = N'v_BuyersOrder_30';


GO
EXECUTE sp_addextendedproperty @name = N'MS_DiagramPaneCount', @value = 2, @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'VIEW', @level1name = N'v_BuyersOrder_30';

